// pages/transaction/select/select.js
import api from '../../../api/api.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    productName: '',
    productList: [],
    loading: false,
    noSearch: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  toBuy(e){
    wx.navigateTo({
      url: `/pages/transaction/buy/buy?productId=${e.target.dataset.productId}`
    })
  },
  bindKeyInput(e) {
    this.setData({
      productName: e.detail
    })
  },
  searchProduct() {
    this.setData({
      loading: true,
      noSearch: false
    });
    api.searchProduct({
      productName: this.data.productName
    }).then(res => {
      if (res.code === '0') {
        this.setData({
          loading: false,
          productList: res.data.financeProductList
        });
      }
    })
  }
});